var Main = {
	data() {
		return {
			allcareoptions: [{
				value: '选项1',
				label: '全部数据'
			}, {
				value: '选项2',
				label: '分类一'
			}, {
				value: '选项3',
				label: '分类二'
			}, {
				value: '选项4',
				label: '分类三'
			}],
			allcareinfor: '',
			caretheme: ''
		}

	}
}
var Ctor = Vue.extend(Main)
new Ctor().$mount('#app1')


/* 遮罩层 */
var Main = {
	data() {
		return {
			allcustomer:[],
			allcustomers:[],
			allcontact:[],
			allcontacts:[],
			alldoname:[],
			alldonames:[],
			allcareclassity:[],
			allcareclassities:[],
			formLabelWidth: "300px",
			careform: {
				ID:'',
				caretheme: '',
				custID: '',
				contID: '',
				caredate: '',
				doname: '',
				careclassity: '',
				textcare: '',
				custreturn: '',
				textremark: '',
			},
			dialogFormVisible: false,
			cumloading:false,
			carerules: {
				caretheme: [{
					required: true,
					message: '请输入投诉主题',
					trigger: 'change'
				}],
				caredate: [{
					required: true,
					message: '请选择日期',
					trigger: 'change'
				}]
			}
		};
	},
	methods: {
		querySearchAsync(queryString, cb) {
			var restaurants = this.restaurants;
			var results = queryString ? restaurants.filter(this.createStateFilter(queryString)) : restaurants;

			clearTimeout(this.timeout);
			this.timeout = setTimeout(() => {
				cb(results);
			}, 3000 * Math.random());
		},
		createStateFilter(queryString) {
			return (state) => {
				return (state.value.toLowerCase().indexOf(queryString.toLowerCase()) === 0);
			};
		},
		handleSelect(item) {
			console.log(item);
		},
		mounted() {
			this.restaurants = this.loadAll();
		},
		 //加载界面客户
		cumremoteMethod(query) {
			var _this=this;
		      if (query !== '') {
		        this.cumloading = true;
		        setTimeout(() => {
		          this.cumloading = false;
		          this.allcustomer = _this.allcustomers.filter(item => {
		            return item.label.toLowerCase()
		              .indexOf(query.toLowerCase()) > -1;
		          });
		        }, 200);
		      } else {
		        this.uosign = [];
		      }
		    },
		//清除客户
		carecustidto(){
			var _this=this;
			_this.allcustomer=_this.allcustomers;
		},
		//加载界面联系人
		contactMethod(query) {
			var _this=this;
			if (query !== '') {
				this.cumloading = true;
				setTimeout(() => {
					this.cumloading = false;
					this.allcontact = _this.allcontacts.filter(item => {
						return item.label.toLowerCase()
						.indexOf(query.toLowerCase()) > -1;
					});
				}, 200);
			} else {
				this.uosign = [];
			}
		},
		//加载界面执行人
		donameMethod(query) {
			var _this=this;
			if (query !== '') {
				this.cumloading = true;
				setTimeout(() => {
					this.cumloading = false;
					this.alldoname = _this.alldonames.filter(item => {
						return item.label.toLowerCase()
						.indexOf(query.toLowerCase()) > -1;
					});
				}, 200);
			} else {
				this.uosign = [];
			}
		},
		//加载界面客户关怀类型
		careclassityMethod(query) {
			var _this=this;
			if (query !== '') {
				this.cumloading = true;
				setTimeout(() => {
					this.cumloading = false;
					this.allcareclassity = _this.allcareclassities.filter(item => {
						return item.label.toLowerCase()
						.indexOf(query.toLowerCase()) > -1;
					});
				}, 200);
			} else {
				this.uosign = [];
			}
		},
		//获取数据
		getNew(){
			var _this=this;
			this.dialogFormVisible=true;
			axios.post("/aftersale/chooseCareOptions",

			).then(function(v) {
					console.log("回调成功，获取了服务器端返回的值v");
					console.log(v);
					console.log("234543332");
					//获取客户
					_this.allcustomer= v.data.customerInfo.map(item => {
						return { value: item.ID, label: item.name };
					});
					_this.allcustomers=_this.allcustomer;
					console.log(_this.allcustomers);
					//获取执行人
					console.log(v.data.careClassifyInfo);
					_this.alldoname= v.data.userInfo.map(item => {
						return { value: item.ID, label: item.name };
					});
					_this.alldonames=_this.alldoname;
					//获取分类
					_this.allcareclassity= v.data.careClassifyInfo.map(item => {
						return { value: item.dictId, label: item.dictName };
					});
					_this.allcareclassities=_this.allcareclassity;
				})/*.catch(function() {
					alert("出错了");
				})*/;
		},
		//清除客户及其对应联系人
		carecustidto(){
			var _this=this;
			_this.allcustomer=_this.allcustomers;
			_this.careform.custID='';
			_this.careform.contID='';
		},
		//清空联系人
		comcontidto(){
			var _this=this;
			_this.allcontact=_this.allcontacts;
			_this.careform.contID='';
		},
		//选择客户查询对应的联系人
		selectOnechange(){
			//选择客户加载联系人
			var _this=this;
			axios.post("/aftersale/custTocon",
			Qs.stringify({
			'custid':_this.careform.custID
			}
			,{arrayFormat: 'brackets'})
			).then(function(v){					          				
			console.log("回调成功，获取了服务器端返回的值v");
			console.log(v.data.comcustmanid);
			_this.allcontact= v.data.comcustmanid.map(item => {
				return { value: item.ID, label: item.name };
			}); 
				_this.addcontel=v.data.comcustmanid;
			//_this.orderes
			})/*.catch(function(){
			  console.log("信息出错了");
			})*/;			
		},
		submitForm(careform) {
			var _this=this;
			this.$refs[careform].validate((valid) => {
				if (valid) {
					//post提交数据
					axios.post("/aftersale/addCare",
						//参数转换
						Qs.stringify(this.careform, {
							arrayFormat: 'brackets'
						})
						//id:
						//ajax请求成功的回调函数
					).then(function(v) {
						console.log("回调成功，获取了服务器端返回的值v");
						console.log(v);
						  _this.$message({
		           			showClose: true,
							type: 'success',
							message: '添加成功!',
							duration:3000,
							center: true
						});
		           		//延时两秒刷新
		           		setTimeout(function (){
		           			window.location.href = '/aftersale/care';
		           		}, 2000);
					}).catch(function() {
						//alert("出错了");
						_this.$message({
		           			showClose: true,
							type: 'success',
							message: '添加失败!',
							duration:3000,
							center: true
						});
					});
				} else {
					console.log('error submit!!');
					return false;
				}
			});
		},
		resetForm(formName) {
			this.$refs[formName].resetFields();
		}
	}
}

var Ctor = Vue.extend(Main)
new Ctor().$mount('#app2')



/*  表单  */
var Main = {
	data() {
		return {
			allcustomer:[],
			allcustomers:[],
			allcontact:[],
			allcontacts:[],
			alldoname:[],
			alldonames:[],
			allcareclassity:[],
			allcareclassities:[],
			caretable:carelist,
			/* caretable: [{
				ID: '20161123',
				caretheme: '给客户寄送资料',
				careContacts: 'mike',
				carecust: '张三',
				caredate: '2018-09-25',
				caretype: '',
				carehasman: '张三',
				caredoman: 'rose'
			}, {
				ID: '20161123',
				caretheme: '给客户寄送资料',
				careContacts: 'mike',
				carecust: '张三',
				caredate: '2018-09-25',
				caretype: '',
				carehasman: '张三',
				caredoman: 'rose'
			}, {
				ID: '20161123',
				caretheme: '给客户寄送资料',
				careContacts: 'mike',
				carecust: '张三',
				caredate: '2018-09-25',
				caretype: '',
				carehasman: '张三',
				caredoman: 'rose'
			}, {
				ID: '20161123',
				caretheme: '给客户寄送资料',
				careContacts: 'mike',
				carecust: '张三',
				caredate: '2018-09-25',
				caretype: '',
				carehasman: '张三',
				caredoman: 'rose'
			}], */
			pages: pageinfo,
			currentPage4: pageinfo.pageNum,
			multipleSelection: [],
			dialogFormVisible: false,
			dialogDelete: false,
			cumloading:false,
			formLabelWidth: "300px",
			careform: {
				caretheme: '',
				custID: '',
				contID: '',
				caredate: '',
				doname: '',
				careclassity: '',
				textcare: '',
				custreturn: '',
				textremark: '',
			},
			carerules: {
				caretheme: [{
					required: true,
					message: '请输入投诉主题',
					trigger: 'change'
				}],
				caredate: [{
					required: true,
					message: '请选择日期',
					trigger: 'change'
				}]
			}
		}
	},
	methods: {
		handleClick(row) {
			console.log(row);
		},
		handleSelectionChange(val) {
			this.multipleSelection = val;
		},
		handleSizeChange(val) {
			window.location.href = '/aftersale/care?pageSize=' + val;

		},
		handleCurrentChange(val) {
			window.location.href = '/aftersale/care?pageNum=' + val;
		},
		querySearchAsync(queryString, cb) {
			var restaurants = this.restaurants;
			var results = queryString ? restaurants.filter(this.createStateFilter(queryString)) : restaurants;

			clearTimeout(this.timeout);
			this.timeout = setTimeout(() => {
				cb(results);
			}, 3000 * Math.random());
		},
		createStateFilter(queryString) {
			return (state) => {
				return (state.value.toLowerCase().indexOf(queryString.toLowerCase()) === 0);
			};
		},
		handleSelect(item) {
			console.log(item);
		},
		mounted() {
			this.restaurants = this.loadAll();
		},
		//加载界面客户
		cumremoteMethod(query) {
			var _this=this;
		      if (query !== '') {
		        this.cumloading = true;
		        setTimeout(() => {
		          this.cumloading = false;
		          this.allcustomer = _this.allcustomers.filter(item => {
		            return item.label.toLowerCase()
		              .indexOf(query.toLowerCase()) > -1;
		          });
		        }, 200);
		      } else {
		        this.uosign = [];
		      }
		    },
		//清除客户及其对应联系人
		carecustidto(){
			var _this=this;
			_this.allcustomer=_this.allcustomers;
			_this.careform.custID='';
			_this.careform.contID='';
		},
		//清空联系人
		comcontidto(){
			var _this=this;
			_this.allcontact=_this.allcontacts;
			_this.careform.contID='';
		},
		//选择客户查询对应的联系人
		selectOnechange(){
			//选择客户加载联系人
			var _this=this;
			axios.post("/aftersale/custTocon",
			Qs.stringify({
			'custid':_this.careform.custID
			}
			,{arrayFormat: 'brackets'})
			).then(function(v){					          				
			console.log("回调成功，获取了服务器端返回的值v");
			console.log(v.data.comcustmanid);
			_this.allcontact= v.data.comcustmanid.map(item => {
				return { value: item.ID, label: item.name };
			}); 
				_this.addcontel=v.data.comcustmanid;
			//_this.orderes
			})/*.catch(function(){
			  console.log("信息出错了");
			})*/;			
		},
		//加载界面联系人
		contactMethod(query) {
			var _this=this;
			if (query !== '') {
				this.cumloading = true;
				setTimeout(() => {
					this.cumloading = false;
					this.allcontact = _this.allcontacts.filter(item => {
						return item.label.toLowerCase()
						.indexOf(query.toLowerCase()) > -1;
					});
				}, 200);
			} else {
				this.uosign = [];
			}
		},
		//加载界面执行人
		donameMethod(query) {
			var _this=this;
			if (query !== '') {
				this.cumloading = true;
				setTimeout(() => {
					this.cumloading = false;
					this.alldoname = _this.alldonames.filter(item => {
						return item.label.toLowerCase()
						.indexOf(query.toLowerCase()) > -1;
					});
				}, 200);
			} else {
				this.uosign = [];
			}
		},
		//加载界面客户关怀类型
		careclassityMethod(query) {
			var _this=this;
			if (query !== '') {
				this.cumloading = true;
				setTimeout(() => {
					this.cumloading = false;
					this.allcareclassity = _this.allcareclassities.filter(item => {
						return item.label.toLowerCase()
						.indexOf(query.toLowerCase()) > -1;
					});
				}, 200);
			} else {
				this.uosign = [];
			}
		},
		
		/**
		 * 打开遮罩层
		 */
		updatehandleClick(row) {
			this.dialogFormVisible = true;
			var _this = this;
			console.log(_this);
			console.log(row);
			axios.post("/aftersale/careOne",
				Qs.stringify( {
			   			'c_id':row.ID,
				   },{arrayFormat: 'brackets'}) 
			).then(function(v) {
				console.log("回调成功，获取了服务器端返回的值v");
				console.log(v.data.careInfo);
				//获取客户
				_this.allcustomer= v.data.customerInfo.map(item => {
					return { value: item.u_id, label: item.u_name };
				});
				_this.allcustomers=_this.allcustomer;
				//获取执行人
				console.log(v.data.careClassifyInfo);
				_this.alldoname= v.data.userInfo.map(item => {
					return { value: item.ID, label: item.name };
				});
				_this.alldonames=_this.alldoname;
				//获取分类
				_this.allcareclassity= v.data.careClassifyInfo.map(item => {
					return { value: item.dictId, label: item.dictName };
				});
				_this.allcareclassities=_this.allcareclassity;
				//传值
				_this.careform.caretheme=v.data.careInfo.caretheme;
				_this.careform.custID=v.data.careInfo.carecust;
				_this.careform.contID=v.data.careInfo.careContacts;
				_this.careform.caredate=v.data.careInfo.caredate;
				_this.careform.doname=v.data.careInfo.carehasman;
				_this.careform.careclassity=v.data.careInfo.caretype;
				_this.careform.textcare=v.data.careInfo.textcare;
				_this.careform.custreturn=v.data.careInfo.custreturn;
				_this.careform.textremark=v.data.careInfo.textremark;
			})/* .catch(function() {
				alert("出错了");
			} )*/;
			this.dialogFormVisible = true;
		},
		//表单提交修改
		submitForm(careform) {
			var _this=this;
			this.$refs[careform].validate((valid) => {
				if (valid) {
					//post提交数据
					axios.post("/aftersale/updateCare",
						//参数转换
						Qs.stringify(this.careform, {
							arrayFormat: 'brackets'
						})
						//id:
						//ajax请求成功的回调函数
					).then(function(v) {
						console.log("回调成功，获取了服务器端返回的值v");
						console.log(v);
						  _this.$message({
		           			showClose: true,
							type: 'success',
							message: '修改成功!',
							duration:3000,
							center: true
						});
		           		//延时两秒刷新
		           		setTimeout(function (){
		           			window.location.href = '/aftersale/care';
		           		}, 2000);
					}).catch(function() {
						//alert("出错了");
						_this.$message({
		           			showClose: true,
							type: 'success',
							message: '修改失败!',
							duration:3000,
							center: true
						});
					});
				} else {
					console.log('error submit!!');
					return false;
				}
			});
		},
		resetForm(formName) {
			this.$refs[formName].resetFields();
		},
		deletenew(ID){
			this.ID=ID;
			this.dialogDelete=true;
			
		},
		//删除方法
		Delete(){
			var _this=this;
			console.log(_this);
			axios.get("/aftersale/caredeleteone",
           			//参数转换
           			//Qs.stringify(this.form,{arrayFormat: 'brackets'})
           			//ajax请求成功的回调函数
           			{
						params:{
							ID:_this.ID
						}
           			}
          			).then(function(response){					          				
           			console.log("回调成功，获取了服务器端返回的值v");
           			console.log(response.data);					           		
           		_this.restaurants=response.data;
           		/*this.$message({
					type: 'success',
					message: '删除成功!'
				});*/
           		//alert("删除成功！");

           		_this.$message({
           			showClose: true,
					type: 'success',
					message: '删除成功!',
					duration:3000,
					center: true
				});
           		//延时两秒刷新
           		setTimeout(function (){
           			window.location.href = '/aftersale/care';
           		}, 2000);

           	}).catch(function(){
           		//alert("删除失败！");
           		_this.$message({
					type: 'error',
					message: '删除失败!',
					duration:3000,
					center: true
				});
           	});	//这个是数据的初始化
	      },
	      downloadfile(){
	    	  window.location.href ="/aftersale/CareExcelDownloads";
	      }
		/*deletenew() {
			this.$confirm('此操作将删除该条记录, 是否继续?', '提示', {
				confirmButtonText: '确定',
				cancelButtonText: '取消',
				type: 'warning',
				center: true
			}).then(() => {
				this.$message({
					type: 'success',
					message: '删除成功!'
				});
			}).catch(() => {
				this.$message({
					type: 'info',
					message: '已取消删除'
				});
			});
		}*/
	}
}
var Ctor = Vue.extend(Main)
new Ctor().$mount('#app3')
